package com.egg.action;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.egg.action.common.BaseAction;
import com.egg.service.DeptService;
/**
 * @项目名称：egg   
 * @类名称：DeptAction   
 * @类描述：部门action   
 * @创建人：wangchenyang
 * @创建时间：2012-9-3 下午3:29:11   
 * @修改人：
 * @修改时间：   
 * @修改备注：   
 * @version
 */
@ParentPackage("default")
@Namespace("/dept")
public class DeptAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private List<Map<String,Object>> deptList;
	private String deptName;
	private String deptDesc;
	private String deptId;
	
	@Autowired
	DeptService deptService;
	
	@Action(value="getAllDept",results={@Result(name="success",location="/system/dept/listDepartment.jsp")})
	public String getAllDept(){
		deptList=deptService.getAllDept();
		return "success";
	}
	@Action(value="preUpdateDept",results={@Result(name="success",location="/system/dept/addOrUpdateDept.jsp")})
	public String preUpdateDept(){
		deptList=deptService.getOenDept(deptId);
		return "success";
	}
	@Action(value="addOrUpdateDept",results={@Result(name="redirect",type="redirect",location="getAllDept.action")})
	public String addOrUpdateDept(){
		if(deptId!=null&&!"".equals(deptId)){
			deptService.updateDept(deptName,deptDesc,deptId);
		}else{
			deptService.addDept(deptName,deptDesc,new Date());
		}
		return "redirect";
	}
	@Action(value="deleteDept",results={@Result(name="redirect",type="redirect",location="getAllDept.action")})
	public String deleteDept(){
		deptService.deleteDept(deptId);
		return "redirect";
	}
	public List<Map<String, Object>> getDeptList() {
		return deptList;
	}
	public void setDeptList(List<Map<String, Object>> deptList) {
		this.deptList = deptList;
	}
	public String getDeptName() {
		return deptName;
	}
	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}
	public String getDeptDesc() {
		return deptDesc;
	}
	public void setDeptDesc(String deptDesc) {
		this.deptDesc = deptDesc;
	}
	public String getDeptId() {
		return deptId;
	}
	public void setDeptId(String deptId) {
		this.deptId = deptId;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
}
